﻿using System;


namespace Zsa.Emulation.Util
{
    /// <summary>
    /// Interface for a generic weak reference.
    /// </summary>
    /// <typeparam name="TObj">The object type.</typeparam>
    public interface IGenericWeakReference<TObj>
     where TObj : class
    {

        /// <summary>
        /// Gets the address.
        /// </summary>
        /// <value>The address.</value>
        IntPtr Address { get; }
        /// <summary>
        /// Gets a value indicating whether this instance is alive.
        /// </summary>
        /// <value><c>true</c> if this instance is alive; otherwise, <c>false</c>.</value>
        bool IsAlive { get; }
        /// <summary>
        /// Gets the target.
        /// </summary>
        /// <value>The target.</value>
        TObj Target { get; }
        /// <summary>
        /// Accquires the strong reference.
        /// </summary>
        /// <returns></returns>
        bool AccquireStrongReference();
        /// <summary>
        /// Releases the strong reference.
        /// </summary>
        void ReleaseStrongReference();
        /// <summary>
        /// Attempts to get a reference to the object.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        bool TryGetReference(out TObj obj);
        /// <summary>
        /// Attempts to get a reference to the object.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="obj">address of variable to put obj in</param>
        /// <returns><c>true</c> if this instance is alive; otherwise, <c>false</c>.</returns>
        bool TryGetReference(PersistReferenceType persist, out TObj obj);
        
    }
}
